<?php
class FrontController{
  private $params;
  private static $frontController;
  private $view;
  private function __construct()
  {
    $this->view = new View();
    $this->params = $_REQUEST;
    // TODO: вырезать все вражеские параметры
  }
  public static function instance()
  {
    if(null == FrontController::$frontController){
      FrontController::$frontController = new FrontController();
    }
    return FrontController::$frontController;
  }
  public function run()
  {
    $size = sizeof($this->params);
    

    $action = (empty($this->params['action'])) ? 'index' : $this->params['action'];
    
    if($size < 1 || empty($this->params['controller'])){
      $actionController = ActionControllerFabric::getController("Index", $this->view, $action);
    }else{
      switch ($this->params['controller']){
        case 'User':
          $actionController = ActionControllerFabric::getController("User", $this->view, $action, $this->params);
          break;
        case 'Post':
          $actionController = ActionControllerFabric::getController("Post", $this->view, $action, $this->params);
          break;
        default:
          $actionController = ActionControllerFabric::getController("Index", $this->view, $action);
      }
    }
    $actionController->run(); // TODO: проверить на наличие объекта $actionController
    $this->view->render();
  }
}
?>